//
//  SSProgressHUD.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/3/30.
//

import UIKit


class SSProgressHUD: UIView {
    
    var iconView = UIView()
    var activityIndicatorView = UIActivityIndicatorView()
    
    static let share: SSProgressHUD = {
        let instance = SSProgressHUD()
        instance.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight)
        
        let iconView = UIView()
        let size:CGFloat = 70
        iconView.frame = CGRect(x: (instance.frame.width - size)/2.0, y: (instance.frame.height - size)/2.0, width: size, height: size)
        iconView.backgroundColor = UIColor.black
        iconView.layer.masksToBounds = true
        iconView.layer.cornerRadius = 4
        instance.addSubview(iconView)
        instance.iconView = iconView

        let activityIndicatorView = UIActivityIndicatorView()
        activityIndicatorView.frame.size = iconView.frame.size
        activityIndicatorView.backgroundColor = UIColor.clear
        activityIndicatorView.style = .whiteLarge
        activityIndicatorView.hidesWhenStopped = true
        iconView.addSubview(activityIndicatorView)
        instance.activityIndicatorView = activityIndicatorView
        
        return instance
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
   

    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        
        self.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenHeight)
        let instance = self
        
        let iconView = UIView()
        let size:CGFloat = 70
        iconView.frame = CGRect(x: (instance.frame.width - size)/2.0, y: (instance.frame.height - size)/2.0, width: size, height: size)
        iconView.backgroundColor = UIColor.black
        iconView.layer.masksToBounds = true
        iconView.layer.cornerRadius = 4
        instance.addSubview(iconView)
        instance.iconView = iconView

        let activityIndicatorView = UIActivityIndicatorView()
        activityIndicatorView.frame.size = iconView.frame.size
        activityIndicatorView.backgroundColor = UIColor.clear
        activityIndicatorView.style = .whiteLarge
        activityIndicatorView.hidesWhenStopped = true
        iconView.addSubview(activityIndicatorView)
        instance.activityIndicatorView = activityIndicatorView
    }
    
    
    func show() {
        keyWindow?.addSubview(self)
        self.activityIndicatorView.startAnimating()
    }
    func dismiss() {
        self.removeFromSuperview()
        self.activityIndicatorView.stopAnimating()
    }

}
